
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>UCTB.model.STMeta &#8212; UCTB  documentation</title>
    <link rel="stylesheet" href="../../../_static/nature.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">UCTB  documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for UCTB.model.STMeta</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">keras</span>
<span class="kn">import</span> <span class="nn">tensorflow</span> <span class="k">as</span> <span class="nn">tf</span>

<span class="kn">from</span> <span class="nn">..model_unit</span> <span class="k">import</span> <span class="n">BaseModel</span>
<span class="kn">from</span> <span class="nn">..model_unit</span> <span class="k">import</span> <span class="n">GAL</span><span class="p">,</span> <span class="n">GCL</span>
<span class="kn">from</span> <span class="nn">..model_unit</span> <span class="k">import</span> <span class="n">DCGRUCell</span>
<span class="kn">from</span> <span class="nn">..model_unit</span> <span class="k">import</span> <span class="n">GCLSTMCell</span>


<div class="viewcode-block" id="STMeta"><a class="viewcode-back" href="../../../UCTB.model.html#UCTB.model.STMeta.STMeta">[docs]</a><span class="k">class</span> <span class="nc">STMeta</span><span class="p">(</span><span class="n">BaseModel</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            num_node(int): Number of nodes in the graph, e.g. number of stations in NYC-Bike dataset.</span>
<span class="sd">            external_dim(int): Dimension of the external feature, e.g. temperature and wind are two dimension.</span>
<span class="sd">            closeness_len(int): The length of closeness data history. The former consecutive ``closeness_len`` time slots</span>
<span class="sd">            of data will be used as closeness history.</span>
<span class="sd">            period_len(int): The length of period data history. The data of exact same time slots in former consecutive</span>
<span class="sd">            ``period_len`` days will be used as period history.</span>
<span class="sd">            trend_len(int): The length of trend data history. The data of exact same time slots in former consecutive</span>
<span class="sd">            ``trend_len`` weeks (every seven days) will be used as trend history.</span>
<span class="sd">            num_graph(int): Number of graphs used in STMeta.</span>
<span class="sd">            gcn_k(int): The highest order of Chebyshev Polynomial approximation in GCN.</span>
<span class="sd">            gcn_layers(int): Number of GCN layers.</span>
<span class="sd">            gclstm_layers(int): Number of STRNN layers, it works on all modes of STMeta such as GCLSTM and DCRNN.</span>
<span class="sd">            num_hidden_units(int): Number of hidden units of RNN.</span>
<span class="sd">            num_dense_units(int): Number of dense units.</span>
<span class="sd">            graph_merge_gal_units(int): Number of units in GAL for merging different graph features.</span>
<span class="sd">                Only works when graph_merge=&#39;gal&#39;</span>
<span class="sd">            graph_merge_gal_num_heads(int): Number of heads in GAL for merging different graph features.</span>
<span class="sd">                Only works when graph_merge=&#39;gal&#39;</span>
<span class="sd">            temporal_merge_gal_units(int): Number of units in GAL for merging different temporal features.</span>
<span class="sd">                Only works when temporal_merge=&#39;gal&#39;</span>
<span class="sd">            temporal_merge_gal_num_heads(int): Number of heads in GAL for merging different temporal features.</span>
<span class="sd">                Only works when temporal_merge=&#39;gal&#39;</span>
<span class="sd">            st_method(str): must in [&#39;GCLSTM&#39;, &#39;DCRNN&#39;, &#39;GRU&#39;, &#39;LSTM&#39;], which refers to different</span>
<span class="sd">                spatial-temporal modeling methods.</span>
<span class="sd">                &#39;GCLSTM&#39;: GCN for modeling spatial feature, LSTM for modeling temporal feature.</span>
<span class="sd">                &#39;DCRNN&#39;: Diffusion Convolution for modeling spatial feature, GRU for modeling temporam frature.</span>
<span class="sd">                &#39;GRU&#39;: Ignore the spatial, and model the temporal feature using GRU</span>
<span class="sd">                &#39;LSTM&#39;: Ignore the spatial, and model the temporal feature using LSTM</span>
<span class="sd">            temporal_merge(str): must in [&#39;gal&#39;, &#39;concat&#39;], refers to different temporal merging methods,</span>
<span class="sd">                &#39;gal&#39;: merge using GAL,</span>
<span class="sd">                &#39;concat&#39;: merge by concat and dense</span>
<span class="sd">            graph_merge(str): must in [&#39;gal&#39;, &#39;concat&#39;], refers to different graph merging methods,</span>
<span class="sd">                &#39;gal&#39;: merge using GAL,</span>
<span class="sd">                &#39;concat&#39;: merge by concat and dense</span>
<span class="sd">            output_activation(function): activation function, e.g. tf.nn.tanh</span>
<span class="sd">            lr(float): Learning rate. Default: 1e-5</span>
<span class="sd">            code_version(str): Current version of this model code, which will be used as filename for saving the model</span>
<span class="sd">            model_dir(str): The directory to store model files. Default:&#39;model_dir&#39;.</span>
<span class="sd">            gpu_device(str): To specify the GPU to use. Default: &#39;0&#39;.</span>
<span class="sd">        &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                 <span class="n">num_node</span><span class="p">,</span>
                 <span class="n">external_dim</span><span class="p">,</span>
                 <span class="n">closeness_len</span><span class="p">,</span>
                 <span class="n">period_len</span><span class="p">,</span>
                 <span class="n">trend_len</span><span class="p">,</span>

                 <span class="c1"># gcn parameters</span>
                 <span class="n">num_graph</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                 <span class="n">gcn_k</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                 <span class="n">gcn_layers</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                 <span class="n">gclstm_layers</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>

                 <span class="c1"># dense units</span>
                 <span class="n">num_hidden_units</span><span class="o">=</span><span class="mi">64</span><span class="p">,</span>
                 <span class="c1"># LSTM units</span>
                 <span class="n">num_dense_units</span><span class="o">=</span><span class="mi">32</span><span class="p">,</span>

                 <span class="c1"># merge parameters</span>
                 <span class="n">graph_merge_gal_units</span><span class="o">=</span><span class="mi">32</span><span class="p">,</span>
                 <span class="n">graph_merge_gal_num_heads</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
                 <span class="n">temporal_merge_gal_units</span><span class="o">=</span><span class="mi">64</span><span class="p">,</span>
                 <span class="n">temporal_merge_gal_num_heads</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>

                 <span class="c1"># network structure parameters</span>
                 <span class="n">st_method</span><span class="o">=</span><span class="s1">&#39;GCLSTM&#39;</span><span class="p">,</span>  <span class="c1"># gclstm</span>
                 <span class="n">temporal_merge</span><span class="o">=</span><span class="s1">&#39;gal&#39;</span><span class="p">,</span>  <span class="c1"># gal</span>
                 <span class="n">graph_merge</span><span class="o">=</span><span class="s1">&#39;gal&#39;</span><span class="p">,</span>  <span class="c1"># concat</span>

                 <span class="n">output_activation</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">sigmoid</span><span class="p">,</span>

                 <span class="n">lr</span><span class="o">=</span><span class="mf">1e-4</span><span class="p">,</span>
                 <span class="n">code_version</span><span class="o">=</span><span class="s1">&#39;STMeta-QuickStart&#39;</span><span class="p">,</span>
                 <span class="n">model_dir</span><span class="o">=</span><span class="s1">&#39;model_dir&#39;</span><span class="p">,</span>
                 <span class="n">gpu_device</span><span class="o">=</span><span class="s1">&#39;0&#39;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">STMeta</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">code_version</span><span class="o">=</span><span class="n">code_version</span><span class="p">,</span> <span class="n">model_dir</span><span class="o">=</span><span class="n">model_dir</span><span class="p">,</span> <span class="n">gpu_device</span><span class="o">=</span><span class="n">gpu_device</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_num_node</span> <span class="o">=</span> <span class="n">num_node</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_gcn_k</span> <span class="o">=</span> <span class="n">gcn_k</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_gcn_layer</span> <span class="o">=</span> <span class="n">gcn_layers</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_graph_merge_gal_units</span> <span class="o">=</span> <span class="n">graph_merge_gal_units</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_graph_merge_gal_num_heads</span> <span class="o">=</span> <span class="n">graph_merge_gal_num_heads</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_temporal_merge_gal_units</span> <span class="o">=</span> <span class="n">temporal_merge_gal_units</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_temporal_merge_gal_num_heads</span> <span class="o">=</span> <span class="n">temporal_merge_gal_num_heads</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_gclstm_layers</span> <span class="o">=</span> <span class="n">gclstm_layers</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_num_graph</span> <span class="o">=</span> <span class="n">num_graph</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_external_dim</span> <span class="o">=</span> <span class="n">external_dim</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_output_activation</span> <span class="o">=</span> <span class="n">output_activation</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_st_method</span> <span class="o">=</span> <span class="n">st_method</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_temporal_merge</span> <span class="o">=</span> <span class="n">temporal_merge</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_graph_merge</span> <span class="o">=</span> <span class="n">graph_merge</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_closeness_len</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">closeness_len</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_period_len</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">period_len</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_trend_len</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">trend_len</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_num_hidden_unit</span> <span class="o">=</span> <span class="n">num_hidden_units</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_num_dense_units</span> <span class="o">=</span> <span class="n">num_dense_units</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_lr</span> <span class="o">=</span> <span class="n">lr</span>
    
<div class="viewcode-block" id="STMeta.build"><a class="viewcode-back" href="../../../UCTB.model.html#UCTB.model.STMeta.STMeta.build">[docs]</a>    <span class="k">def</span> <span class="nf">build</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">init_vars</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">max_to_keep</span><span class="o">=</span><span class="mi">5</span><span class="p">):</span>
        <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">_graph</span><span class="o">.</span><span class="n">as_default</span><span class="p">():</span>

            <span class="n">temporal_features</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_closeness_len</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_closeness_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">closeness_feature</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">placeholder</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">float32</span><span class="p">,</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_closeness_len</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
                                                   <span class="n">name</span><span class="o">=</span><span class="s1">&#39;closeness_feature&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_input</span><span class="p">[</span><span class="s1">&#39;closeness_feature&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">closeness_feature</span><span class="o">.</span><span class="n">name</span>
                <span class="n">temporal_features</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">_closeness_len</span><span class="p">,</span> <span class="n">closeness_feature</span><span class="p">,</span> <span class="s1">&#39;closeness_feature&#39;</span><span class="p">])</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_period_len</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_period_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">period_feature</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">placeholder</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">float32</span><span class="p">,</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_period_len</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
                                                <span class="n">name</span><span class="o">=</span><span class="s1">&#39;period_feature&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_input</span><span class="p">[</span><span class="s1">&#39;period_feature&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">period_feature</span><span class="o">.</span><span class="n">name</span>
                <span class="n">temporal_features</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">_period_len</span><span class="p">,</span> <span class="n">period_feature</span><span class="p">,</span> <span class="s1">&#39;period_feature&#39;</span><span class="p">])</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_trend_len</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_trend_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">trend_feature</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">placeholder</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">float32</span><span class="p">,</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_trend_len</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
                                               <span class="n">name</span><span class="o">=</span><span class="s1">&#39;trend_feature&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_input</span><span class="p">[</span><span class="s1">&#39;trend_feature&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">trend_feature</span><span class="o">.</span><span class="n">name</span>
                <span class="n">temporal_features</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">_trend_len</span><span class="p">,</span> <span class="n">trend_feature</span><span class="p">,</span> <span class="s1">&#39;trend_feature&#39;</span><span class="p">])</span>

            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">temporal_features</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">target</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">placeholder</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">float32</span><span class="p">,</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;target&#39;</span><span class="p">)</span>
                <span class="n">laplace_matrix</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">placeholder</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">float32</span><span class="p">,</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_num_graph</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">],</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;laplace_matrix&#39;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_input</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">target</span><span class="o">.</span><span class="n">name</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_input</span><span class="p">[</span><span class="s1">&#39;laplace_matrix&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">laplace_matrix</span><span class="o">.</span><span class="n">name</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;closeness_len, period_len, trend_len cannot all be zero&#39;</span><span class="p">)</span>

            <span class="n">graph_outputs_list</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="k">for</span> <span class="n">graph_index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_num_graph</span><span class="p">):</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_st_method</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;GCLSTM&#39;</span><span class="p">,</span> <span class="s1">&#39;DCRNN&#39;</span><span class="p">,</span> <span class="s1">&#39;GRU&#39;</span><span class="p">,</span> <span class="s1">&#39;LSTM&#39;</span><span class="p">]:</span>

                    <span class="n">outputs_temporal</span> <span class="o">=</span> <span class="p">[]</span>

                    <span class="k">for</span> <span class="n">time_step</span><span class="p">,</span> <span class="n">target_tensor</span><span class="p">,</span> <span class="n">given_name</span> <span class="ow">in</span> <span class="n">temporal_features</span><span class="p">:</span>

                        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_st_method</span> <span class="o">==</span> <span class="s1">&#39;GCLSTM&#39;</span><span class="p">:</span>

                            <span class="n">multi_layer_cell</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">StackedRNNCells</span><span class="p">(</span>
                                <span class="p">[</span><span class="n">GCLSTMCell</span><span class="p">(</span><span class="n">units</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_num_hidden_unit</span><span class="p">,</span> <span class="n">num_nodes</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_num_node</span><span class="p">,</span>
                                            <span class="n">laplacian_matrix</span><span class="o">=</span><span class="n">laplace_matrix</span><span class="p">[</span><span class="n">graph_index</span><span class="p">],</span>
                                            <span class="n">gcn_k</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_gcn_k</span><span class="p">,</span> <span class="n">gcn_l</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_gcn_layer</span><span class="p">)</span>
                                 <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_gclstm_layers</span><span class="p">)])</span>

                            <span class="n">outputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">RNN</span><span class="p">(</span><span class="n">multi_layer_cell</span><span class="p">)(</span><span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">target_tensor</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">time_step</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))</span>

                            <span class="n">st_outputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_hidden_unit</span><span class="p">])</span>

                        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_st_method</span> <span class="o">==</span> <span class="s1">&#39;DCRNN&#39;</span><span class="p">:</span>

                            <span class="n">cell</span> <span class="o">=</span> <span class="n">DCGRUCell</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_num_hidden_unit</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_graph</span><span class="p">,</span>
                                             <span class="c1"># laplace_matrix will be diffusion_matrix when self._st_method == &#39;DCRNN&#39;</span>
                                             <span class="n">laplace_matrix</span><span class="p">,</span>
                                             <span class="n">max_diffusion_step</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_gcn_k</span><span class="p">,</span>
                                             <span class="n">num_nodes</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_num_node</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">graph_index</span><span class="p">)</span> <span class="o">+</span> <span class="n">given_name</span><span class="p">)</span>

                            <span class="n">encoding_cells</span> <span class="o">=</span> <span class="p">[</span><span class="n">cell</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gclstm_layers</span>
                            <span class="n">encoding_cells</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">contrib</span><span class="o">.</span><span class="n">rnn</span><span class="o">.</span><span class="n">MultiRNNCell</span><span class="p">(</span><span class="n">encoding_cells</span><span class="p">,</span> <span class="n">state_is_tuple</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

                            <span class="n">inputs_unstack</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">unstack</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">target_tensor</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_node</span><span class="p">,</span> <span class="n">time_step</span><span class="p">]),</span>
                                                        <span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>

                            <span class="n">outputs</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> \
                                <span class="n">tf</span><span class="o">.</span><span class="n">contrib</span><span class="o">.</span><span class="n">rnn</span><span class="o">.</span><span class="n">static_rnn</span><span class="p">(</span><span class="n">encoding_cells</span><span class="p">,</span> <span class="n">inputs_unstack</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>

                            <span class="n">st_outputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">outputs</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_hidden_unit</span><span class="p">])</span>

                        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_st_method</span> <span class="o">==</span> <span class="s1">&#39;GRU&#39;</span><span class="p">:</span>

                            <span class="n">cell</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">GRUCell</span><span class="p">(</span><span class="n">units</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_num_hidden_unit</span><span class="p">)</span>
                            <span class="n">multi_layer_gru</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">StackedRNNCells</span><span class="p">([</span><span class="n">cell</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gclstm_layers</span><span class="p">)</span>
                            <span class="n">outputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">RNN</span><span class="p">(</span><span class="n">multi_layer_gru</span><span class="p">)(</span>
                                <span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">target_tensor</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">time_step</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))</span>
                            <span class="n">st_outputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_hidden_unit</span><span class="p">])</span>

                        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_st_method</span> <span class="o">==</span> <span class="s1">&#39;LSTM&#39;</span><span class="p">:</span>

                            <span class="n">cell</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">LSTMCell</span><span class="p">(</span><span class="n">units</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_num_hidden_unit</span><span class="p">)</span>
                            <span class="n">multi_layer_gru</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">StackedRNNCells</span><span class="p">([</span><span class="n">cell</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gclstm_layers</span><span class="p">)</span>
                            <span class="n">outputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">RNN</span><span class="p">(</span><span class="n">multi_layer_gru</span><span class="p">)(</span>
                                <span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">target_tensor</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">time_step</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))</span>
                            <span class="n">st_outputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_hidden_unit</span><span class="p">])</span>

                        <span class="n">outputs_temporal</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">st_outputs</span><span class="p">)</span>

                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_temporal_merge</span> <span class="o">==</span> <span class="s1">&#39;concat&#39;</span><span class="p">:</span>
                        
                        <span class="n">graph_outputs_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">outputs_temporal</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">))</span>

                    <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_temporal_merge</span> <span class="o">==</span> <span class="s1">&#39;gal&#39;</span><span class="p">:</span>

                        <span class="n">_</span><span class="p">,</span> <span class="n">gal_output</span> <span class="o">=</span> <span class="n">GAL</span><span class="o">.</span><span class="n">add_ga_layer_matrix</span><span class="p">(</span><span class="n">inputs</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">outputs_temporal</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">2</span><span class="p">),</span>
                                                                <span class="n">units</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_temporal_merge_gal_units</span><span class="p">,</span>
                                                                <span class="n">num_head</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_temporal_merge_gal_num_heads</span><span class="p">)</span>

                        <span class="n">graph_outputs_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">reduce_mean</span><span class="p">(</span><span class="n">gal_output</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">2</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_graph</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_graph_merge</span> <span class="o">==</span> <span class="s1">&#39;gal&#39;</span><span class="p">:</span>
                    <span class="c1"># (graph, inputs_name, units, num_head, activation=tf.nn.leaky_relu)</span>
                    <span class="n">_</span><span class="p">,</span> <span class="n">gal_output</span> <span class="o">=</span> <span class="n">GAL</span><span class="o">.</span><span class="n">add_ga_layer_matrix</span><span class="p">(</span><span class="n">inputs</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">graph_outputs_list</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">2</span><span class="p">),</span>
                                                            <span class="n">units</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_graph_merge_gal_units</span><span class="p">,</span>
                                                            <span class="n">num_head</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_graph_merge_gal_num_heads</span><span class="p">)</span>
                    <span class="n">dense_inputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">reduce_mean</span><span class="p">(</span><span class="n">gal_output</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">2</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

                <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_graph_merge</span> <span class="o">==</span> <span class="s1">&#39;concat&#39;</span><span class="p">:</span>

                    <span class="n">dense_inputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">graph_outputs_list</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>

            <span class="k">else</span><span class="p">:</span>

                <span class="n">dense_inputs</span> <span class="o">=</span> <span class="n">graph_outputs_list</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

            <span class="n">dense_inputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">dense_inputs</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_node</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">dense_inputs</span><span class="o">.</span><span class="n">get_shape</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">value</span><span class="p">])</span>

            <span class="n">dense_inputs</span> <span class="o">=</span> <span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">BatchNormalization</span><span class="p">(</span><span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;feature_map&#39;</span><span class="p">)(</span><span class="n">dense_inputs</span><span class="p">)</span>

            <span class="c1"># external dims</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_external_dim</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_external_dim</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">external_input</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">placeholder</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">float32</span><span class="p">,</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_external_dim</span><span class="p">])</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_input</span><span class="p">[</span><span class="s1">&#39;external_feature&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">external_input</span><span class="o">.</span><span class="n">name</span>
                <span class="n">external_dense</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="n">units</span><span class="o">=</span><span class="mi">10</span><span class="p">)(</span><span class="n">external_input</span><span class="p">)</span>
                <span class="n">external_dense</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">tile</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">external_dense</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">]),</span>
                                         <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="n">tf</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="n">dense_inputs</span><span class="p">)[</span><span class="mi">1</span><span class="p">],</span> <span class="n">tf</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="n">dense_inputs</span><span class="p">)[</span><span class="mi">2</span><span class="p">],</span> <span class="mi">1</span><span class="p">])</span>
                <span class="n">dense_inputs</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">dense_inputs</span><span class="p">,</span> <span class="n">external_dense</span><span class="p">],</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>

            <span class="n">dense_output0</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="n">units</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_num_dense_units</span><span class="p">,</span>
                                                  <span class="n">activation</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">tanh</span><span class="p">,</span>
                                                  <span class="n">use_bias</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                                  <span class="n">kernel_initializer</span><span class="o">=</span><span class="s1">&#39;glorot_uniform&#39;</span><span class="p">,</span>
                                                  <span class="n">bias_initializer</span><span class="o">=</span><span class="s1">&#39;zeros&#39;</span><span class="p">,</span>
                                                  <span class="n">kernel_regularizer</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">regularizers</span><span class="o">.</span><span class="n">l2</span><span class="p">(</span><span class="mf">0.01</span><span class="p">),</span>
                                                  <span class="n">bias_regularizer</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">regularizers</span><span class="o">.</span><span class="n">l2</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span>
                                                  <span class="p">)(</span><span class="n">dense_inputs</span><span class="p">)</span>

            <span class="n">dense_output1</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="n">units</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_num_dense_units</span><span class="p">,</span>
                                                  <span class="n">activation</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">tanh</span><span class="p">,</span>
                                                  <span class="n">use_bias</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                                  <span class="n">kernel_initializer</span><span class="o">=</span><span class="s1">&#39;glorot_uniform&#39;</span><span class="p">,</span>
                                                  <span class="n">bias_initializer</span><span class="o">=</span><span class="s1">&#39;zeros&#39;</span><span class="p">,</span>
                                                  <span class="n">kernel_regularizer</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">regularizers</span><span class="o">.</span><span class="n">l2</span><span class="p">(</span><span class="mf">0.01</span><span class="p">),</span>
                                                  <span class="n">bias_regularizer</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">regularizers</span><span class="o">.</span><span class="n">l2</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span>
                                                  <span class="p">)(</span><span class="n">dense_output0</span><span class="p">)</span>

            <span class="n">pre_output</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="n">units</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                                               <span class="n">activation</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">tanh</span><span class="p">,</span>
                                               <span class="n">use_bias</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                               <span class="n">kernel_initializer</span><span class="o">=</span><span class="s1">&#39;glorot_uniform&#39;</span><span class="p">,</span>
                                               <span class="n">bias_initializer</span><span class="o">=</span><span class="s1">&#39;zeros&#39;</span><span class="p">,</span>
                                               <span class="n">kernel_regularizer</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">regularizers</span><span class="o">.</span><span class="n">l2</span><span class="p">(</span><span class="mf">0.01</span><span class="p">),</span>
                                               <span class="n">bias_regularizer</span><span class="o">=</span><span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">regularizers</span><span class="o">.</span><span class="n">l2</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span>
                                               <span class="p">)(</span><span class="n">dense_output1</span><span class="p">)</span>

            <span class="n">prediction</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">pre_output</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_node</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;prediction&#39;</span><span class="p">)</span>

            <span class="n">loss_pre</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">reduce_mean</span><span class="p">(</span><span class="n">tf</span><span class="o">.</span><span class="n">square</span><span class="p">(</span><span class="n">target</span> <span class="o">-</span> <span class="n">prediction</span><span class="p">)),</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;loss&#39;</span><span class="p">)</span>

            <span class="n">train_op</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">train</span><span class="o">.</span><span class="n">AdamOptimizer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_lr</span><span class="p">)</span><span class="o">.</span><span class="n">minimize</span><span class="p">(</span><span class="n">loss_pre</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;train_op&#39;</span><span class="p">)</span>

            <span class="c1"># record output</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_output</span><span class="p">[</span><span class="s1">&#39;prediction&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">prediction</span><span class="o">.</span><span class="n">name</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_output</span><span class="p">[</span><span class="s1">&#39;loss&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">loss_pre</span><span class="o">.</span><span class="n">name</span>

            <span class="c1"># record train operation</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_op</span><span class="p">[</span><span class="s1">&#39;train_op&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">train_op</span><span class="o">.</span><span class="n">name</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">STMeta</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="n">init_vars</span><span class="p">,</span> <span class="n">max_to_keep</span><span class="p">)</span></div>

    <span class="c1"># Define your &#39;_get_feed_dict function‘, map your input to the tf-model</span>
    <span class="k">def</span> <span class="nf">_get_feed_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                       <span class="n">laplace_matrix</span><span class="p">,</span>
                       <span class="n">closeness_feature</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                       <span class="n">period_feature</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                       <span class="n">trend_feature</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                       <span class="n">target</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                       <span class="n">external_feature</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">feed_dict</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s1">&#39;laplace_matrix&#39;</span><span class="p">:</span> <span class="n">laplace_matrix</span><span class="p">,</span>
        <span class="p">}</span>
        <span class="k">if</span> <span class="n">target</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">feed_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">target</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_external_dim</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_external_dim</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">feed_dict</span><span class="p">[</span><span class="s1">&#39;external_feature&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">external_feature</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_closeness_len</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_closeness_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">feed_dict</span><span class="p">[</span><span class="s1">&#39;closeness_feature&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">closeness_feature</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_period_len</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_period_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">feed_dict</span><span class="p">[</span><span class="s1">&#39;period_feature&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">period_feature</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_trend_len</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_trend_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">feed_dict</span><span class="p">[</span><span class="s1">&#39;trend_feature&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">trend_feature</span>
        <span class="k">return</span> <span class="n">feed_dict</span></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">UCTB  documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2019, Di Chai, Leye Wang, Jin Xu, Wenjie Yang, Liyue Chen.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.2.1.
    </div>
  </body>
</html>